package com.dubito.service.impl;

import java.util.List;

import com.dubito.dao.impl.UserDaoImpl;
import com.dubito.dao.impl.User_RoleDaoImpl;
import com.dubito.entity.User;
import com.dubito.entity.User_Role;

public class UserServiceImpl {
	
	private UserDaoImpl userDaoImpl = new UserDaoImpl();
	private User_RoleDaoImpl user_roleDaoImpl = new User_RoleDaoImpl();
	
	public boolean addUser(User user){
		boolean flag = false;
		int i = userDaoImpl.insert(user);
		if(i == 1){
			user_roleDaoImpl.insert(new User_Role(userDaoImpl.select(user).getId(), 3));
			flag = true;
		}
		return flag;
	}
	
	/**
	 *  
	 * @描述 给用户添加角色
	 * @param 用户信息
	 * @return true/false
	 */
	public boolean addUser_Role(User user){
		boolean flag = false;
		flag = user_roleDaoImpl
				.insert(new User_Role(userDaoImpl
						.select(user).getId()
						, 3))== 1 ? true : false;
		return flag;
	}
	
	/**
	 * @描述 查询用户拥有的角色
	 * @param user
	 * @return
	 */
	public List<User> selectUser_Role(User user){
		
		return userDaoImpl.selectUser_Role(user);
	}
}
